<template>
    <div style="display:inline-block">
    <div class='form-group-enquire' style="display:inline-block"> 
        <Select v-model="searchData.searchDid" style="width:150px" placeholder="请选择商务主管" @on-change="changeDid()"  clearable filterable>
        <Option :value=row.Uid v-for="row in dList" :label="'('+row.Uid+')'+row.Name" :key=row.Uid><span>{{row.Name}}</span><span style="float:left;color:#FF0000">({{row.Uid}})</span></Option>
        </Select>
    </div>
    <div class='form-group-enquire' style="display:inline-block"> 
        <Select v-model="searchData.searchBid" style="width:150px" placeholder="请选择运营" @on-change="submitChange()"  clearable filterable>
             <Option :value=row.Uid v-for="row in bList" :label="'('+row.Uid+')'+row.Name" :key=row.Uid v-show="filterConsumer(row)"><span>{{row.Name}}</span><span style="float:left;color:#FF0000">({{row.Uid}})</span></Option>
        </Select>
    </div>
    
    </div>
</template>
<script>
import Vue from "vue";
import { mapGetters } from "vuex";
export default {
    name: "SearchUser",
    props:{

    },
    data(){
        return {
            searchData:{
                searchDid:-1,
                searchBid:-1,
            }
        }
    },
    watch:{

    },
    computed:{
        ...mapGetters(["UserInfo","OpUserList","DirectorList","BusinessList","Swzl"]),
        dList(){
            let list = [{"Uid":-1,"Name":"请选择商务主管"}].concat(this.DirectorList);
            return list;
        },
        bList(){
            let list = [{"Uid":-1,"Name":"请选择商务"}].concat(this.BusinessList);
            return list;
        },
    },
    methods:{
        changeDid(){
            this.searchData.searchBid = -1;
            this.submitChange();
        },
        submitChange(){
            this.$emit("submitChange",this.searchData)
        },
        filterConsumer(item){
            if(item.Uid==-1){
                return true;
            }
            else if(this.searchData.searchDid==-1){
                return false;
            }else{
                return item.Leader==this.searchData.searchDid||item.Uid==this.searchData.searchDid;
            }
        }
    },
    mounted(){
        if(this.Swzl){
            this.$nextTick(function () {
                this.$set(this.searchData, "searchBid", this.UserInfo.uid);
            });
            this.searchData.searchBid = this.UserInfo.uid
            let cnt = this.OpUserList.length;
            for(let i = 0;i<cnt;i++){
                if(this.OpUserList[i].Uid == this.UserInfo.uid){
                    this.$nextTick(function () {
                        this.$set(this.searchData, "searchDid", this.OpUserList[i]["Leader"]);
                    });
                    this.searchData.searchDid = this.OpUserList[i]["Leader"]
                    break;
                }
            }
        }
        this.submitChange();
    }
}
</script>
  
